package io.finer.erp.jeecg.sale.entity;

import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.IdType;
import java.util.Date;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;

/**
 * <p>
 * 销售订单
 * </p>
 *
 * @author yaoyifan
 * @since 2021-05-11
 */
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="SaleOrder对象", description="销售订单")
public class SaleOrder implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "ID")
    @TableId(value = "id", type = IdType.ID_WORKER_STR)
    private String id;

    @ApiModelProperty(value = "单据编号")
    private String billNo;

    @ApiModelProperty(value = "单据日期")
    private Date billDate;

    @ApiModelProperty(value = "客户")
    private String customerId;

    @ApiModelProperty(value = "订单总额")
    private BigDecimal amount;

    @ApiModelProperty(value = "附件")
    private String attachment;

    @ApiModelProperty(value = "备注")
    private String remark;

    @ApiModelProperty(value = "处理状态")
    private String billProcStatus;

    @ApiModelProperty(value = "是否作废")
    private Integer isVoided;

    @ApiModelProperty(value = "作废原因")
    private String invalidationReason;

    @ApiModelProperty(value = "创建部门")
    private String sysOrgCode;

    @ApiModelProperty(value = "制单人")
    private String createBy;

    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    @ApiModelProperty(value = "修改人")
    private String updateBy;

    @ApiModelProperty(value = "修改时间")
    private Date updateTime;

    @ApiModelProperty(value = "版本")
    private Integer version;

    @TableField(exist = false)
    private Map actionsEnabled;

    public Map getActionsEnabled() {
        if (id == null) {
            return null;
        }

        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

        HashMap<String, Boolean> map = new HashMap<String, Boolean>();
        boolean b = billProcStatus == "create" && createBy == sysUser.getUsername();
        map.put("edit", b);
        map.put("delete", b);

        b = billProcStatus == "reject" && createBy == sysUser.getUsername();
        map.put("invalid", b);

        b = billProcStatus == "submit" && createBy == sysUser.getUsername();
        map.put("withdraw", b);

        actionsEnabled = map;
        return map;
    }


}
